#!/bin/sh
ding=https://oapi.dingtalk.com/robot/send?access_token=605b3322af99285c0fe8426f42172fc3155efbac6885b8578e3750cce63d8378
ip=8.8.8.8
date=`date +"%y-%m-%d %H:%M:%S"`
dir=`dirname $0`


#ip=www.baidu.com
ping=`ping $ip -c 5|grep trans`
#echo $ping
# ${string%sub*} ${string#*sub} %去年sub后的字符串 #去掉sub前的字符串 双##或者%%表示尽可能多的匹配
# ${#str} str的长度  ${str:start:length} 从左边截取  ${str:0-start:length} 从右边截取
loss=${ping%\%*}
loss=${loss##*,}
#echo $loss


if test $loss -ne 0
then
echo $date
#echo $loss
title=沈阳移动报警
body="### $title \nping $ip \n丢包率 $loss%"
sh $dir/push_ding.sh "$ding" "$title" "$body"
echo $body
echo ""
#else
#echo 未丢包
fi